package com.bing.springboot.config;

import com.bing.springboot.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 徐
 * @version 1.0
 * 配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截器
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**") //拦截所有路径
                .excludePathPatterns("/","/login","/images/**","/upload.html","/upload","/favicon.ico");//指定放行的请求
    }

    //方式二,无需类实现接口，内部类
//    @Bean
//    public WebMvcConfigurer webMvcConfigurer(){
//        return new WebMvcConfigurer() {
//            @Override
//            public void addInterceptors(InterceptorRegistry registry) {
//                //注册自定义拦截器
//                registry.addInterceptor(new LoginInterceptor())
//                        .addPathPatterns("/**") //拦截所有路径
//                        .excludePathPatterns("/","/login","/images/**");//指定放行的请求
//            }
//        };
//    }
}
